#include "../mqserver/mq_exchange.hpp"
#include <gtest/gtest.h>

zlrmq::ExchangeManager::ptr emp;

class ExchangeTest : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        emp = std::make_shared<zlrmq::ExchangeManager>("./data/meta.db");
    }
    virtual void TearDown() override
    {
        //emp->clear();
    }
};

/* TEST(exchange_test, insert_test)
{
    std::unordered_map<std::string, std::string> map = {{"k1", "v1"}, {"k2", "v2"}};
    emp->declareExchange("exchange1",zlrmq::ExchangeType::DIRECT,true,false,map);
    emp->declareExchange("exchange2",zlrmq::ExchangeType::DIRECT,true,false,map);
    emp->declareExchange("exchange3",zlrmq::ExchangeType::DIRECT,true,false,map);
    emp->declareExchange("exchange4",zlrmq::ExchangeType::DIRECT,true,false,map);
    emp->declareExchange("exchange5",zlrmq::ExchangeType::DIRECT,true,false,map);
    ASSERT_EQ(emp->size(),5);
} */

TEST(exchange_test, insert_test)
{
    std::unordered_map<std::string, std::string> map;
    emp->declareExchange("exchange1",zlrmq::ExchangeType::DIRECT,false,false,map);
    emp->declareExchange("exchange2",zlrmq::ExchangeType::DIRECT,true,false,map);
    emp->declareExchange("exchange3",zlrmq::ExchangeType::DIRECT,true,false,map);
    emp->declareExchange("exchange4",zlrmq::ExchangeType::DIRECT,true,false,map);
    emp->declareExchange("exchange5",zlrmq::ExchangeType::DIRECT,true,false,map);
    ASSERT_EQ(emp->size(),5);
}

TEST(exchange_test, remove_test)
{

    emp->deleteExchange("exchange3");
    ASSERT_EQ(emp->exists("exchange3"),false);
}

//TEST(exchange_test, select_test)
//{
   // std::unordered_map<std::string, std::string> map = {{"k1", "v1"}, {"k2", "v2"}};
    //auto exp = emp->selectExchange("exchange3");
    //ASSERT_EQ(exp->name,"exchange3");
    //ASSERT_EQ(exp->type,zlrmq::ExchangeType::DIRECT);
    //ASSERT_EQ(exp->durable,true);
//}



int main(int argc, char *argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new ExchangeTest);
    int ret = RUN_ALL_TESTS();
    (void)ret;
    return 0;
}